<?php
$id = empty($_GET['id']) ? 0 : intval($_GET['id']);
if($id == 0){
	$mark = empty($_GET['mark']) ? '' : trim($_GET['mark']);
	if(empty($mark)){
		go(PUB_DIR.'brand/');
	}
}
$oBrand = new Brand();
if(empty($mark)){
	$brand = $oBrand->get_row($id, '*');
}else{
	$brand = $oBrand->get_by_mark($mark, '*');
}
if(empty($brand)){
	go(PUB_DIR.'brand/');
}
/* if(!empty($brand['url'])){
	go($brand['url']);
} */
$vars['brand'] = $brand;


/*******************************************************************************
 * 关联商品
 *******************************************************************************/
$oGoods = new Goods();
$goods_list = $oGoods->get_list('*', array('brand' => $brand['id']), array('orderby_sales' => 'DESC', 'orderby_views' => 'DESC', 'id' => 'DESC'), 1, 16);
foreach($goods_list['list'] as $key => $goods){
	if($__f_sysvars['url_rewrite'] == 'html' || $__f_sysvars['url_rewrite'] == 'rewrite'){
		if(empty($goods['filename'])){
			$goods['url'] = PUB_DIR.'goods/'.time_to_path($goods['addtime']).'/'.$goods['id'].'.html';
		}else{
			$goods['url'] = PUB_DIR.'goods/'.$goods['filename'].'.html';
		}
	}else{
		$goods['url'] = WEB_DIR."index.php?mdl=goods&do=view&id={$goods['id']}";
	}
	$goods_list['list'][$key] = $goods;
}
$vars['goods_list'] = $goods_list['list'];

// 上一品牌、下一品牌
$brand_prev = $oBrand->get_prev($brand['rank'], $brand['id'], '`id`,`name`,`url`,`mark`,`addtime`');
if(!empty($brand_prev)){
	if($__f_sysvars['url_rewrite'] == 'html' || $__f_sysvars['url_rewrite'] == 'rewrite'){
		if(empty($brand_prev['mark'])){
			$brand_prev['href'] = PUB_DIR.'brand/v/'.$brand_prev['id'].'.html';
		}else{
			$brand_prev['href'] = PUB_DIR.'brand/v/'.$brand_prev['mark'].'.html';
		}
	}else{
		$brand_prev['href'] = WEB_DIR."index.php?mdl=brand&do=view&mark={$brand_prev['mark']}";
	}
	$vars['brand_prev'] = $brand_prev;
}
$brand_next = $oBrand->get_next($brand['rank'], $brand['id'], '`id`,`name`,`url`,`mark`,`addtime`');
if(!empty($brand_next)){
	if($__f_sysvars['url_rewrite'] == 'html' || $__f_sysvars['url_rewrite'] == 'rewrite'){
		if(empty($brand_next['mark'])){
			$brand_next['href'] = PUB_DIR.'brand/v/'.$brand_next['id'].'.html';
		}else{
			$brand_next['href'] = PUB_DIR.'brand/v/'.$brand_next['mark'].'.html';
		}
	}else{
		$brand_next['href'] = WEB_DIR."index.php?mdl=brand&do=view&mark={$brand_next['mark']}";
	}
	$vars['brand_next'] = $brand_next;
}

/*******************************************************************************
 * 页面信息　& 当前位置
 *******************************************************************************/
if($__f_sysvars['url_rewrite'] == 'html' || $__f_sysvars['url_rewrite'] == 'rewrite'){
	if(empty($brand['mark'])){
		$url = PUB_DIR.'brand/v/'.$brand['id'].'.html';
	}else{
		$url = PUB_DIR.'brand/v/'.$brand['mark'].'.html';
	}
}else{
	$url = WEB_DIR."index.php?mdl=brand&id={$brand['id']}";
}
url_here($brand['name'], $url);
$__pageinfo['keywords'] = "{$brand['name']},{$brand['tags']}";
$__pageinfo['description'] = String::summary($brand['content'], 200);
?>